import adminApi from "../../api/admins.js";
import Base from "../Base.js";
import "../../css/index.css";
export default class extends Base {
    handle() {
        this.loginBtn.on("click", async e => {
            // 获取值
            const adminName = this.adminNameInput.val();
            const adminPassword = this.adminPasswordInput.val();
            const data = await adminApi.login({ adminName, adminPassword });
            if (data) {
                location.hash = "#/info";
                const date = (new Date()).toLocaleString()
                sessionStorage.setItem("adminInfo", JSON.stringify({ _id: data._id, date }));
                await adminApi.addDate({ _id: data._id, date });
            }
            else {
                layui.layer.msg("账号或密码错误");
            }
        })
    }
    render() {
        this.el.html(`
        <article class="login-reg-art">
        <h1>猫眼后台管理系统</h1>
        <h2>欢迎登录</h2>
        <div class="tips">
            <p>没有账号?&nbsp;&nbsp;&nbsp;&nbsp;<a href="#/reg">注册</a></p>
        </div>
        <form class="layui-form" action="" style="margin-right:55px;">
            <div class="layui-form-item">
                <label for="user" class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="adminName" required lay-verify="required" placeholder="请输入用户名"
                        autocomplete="off" class="layui-input" id="user">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="pwd" class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                <div class="layui-input-block">
                    <input type="password" name="adminPassword" required lay-verify="required" placeholder="请输入密码"
                        autocomplete="off" class="layui-input" id="pwd">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="margin-left: 55px;">
                    <input type="button" value="登录" class="layui-btn" lay-filter="login" id="login"
                        style="width: 100%;border-radius:19px" ;>
                </div>
            </div>
        </form>
    </article>
        `);
        this.adminNameInput = $("input[name=adminName]");
        this.adminPasswordInput = $("input[name=adminPassword]");
        this.loginBtn = $("#login");
    }
}
